﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Data.Schema.UnitTesting;
using QueueUnlimited.API;
using System.Diagnostics;
using System.Data.SqlClient;

namespace QueueUnlimited.ScenarioTests.Helper
{
    [TestClass]
    public class BaseScenarioTestFixture
    {
        [TestInitialize]
        public void Test_Initialize()
        {
            DatabaseTestClass.TestService.DeployDatabaseProject();
        }

        public void PrintServiceTree(string annotation)
        {
            Trace.IndentLevel = 1;
            Trace.WriteLine("Annotation : " + annotation);
            var rootService = this.MetaData.GetServiceTree();
            PrintRecursive(rootService);
        }

        private void PrintRecursive(MetaData.Service service)
        {
            Trace.WriteLine("-----------------------");
            Trace.WriteLine(service.Name);
            Trace.Indent();
            Trace.Indent();
            foreach (var child in service.Children())
            {
                Trace.WriteLine("Sends to : " + child.Name);
            }
            if (service.OverflowService != null)
            {
                Trace.WriteLine("Overflows to : " + service.OverflowService.Name);
                PrintRecursive(service.OverflowService);
            }
        }
       

        public MetaData MetaData
        {
            get
            {
                return new MetaData(ConnectionStringForTests);
            }
        }

        protected string ConnectionStringForTests
        {
            get
            {
                var x = new SqlConnectionStringBuilder(DatabaseTestClass.TestService.OpenExecutionContext().Connection.ConnectionString);
                x.ConnectTimeout = 60;
                return x.ToString();
            }
        }
    }
}
